#include"Reactor.hpp"
#include"Listener.hpp"
#include"HandlerConnection.hpp"
#include<memory>
#include"NetCal.hpp"
#include"PackageParse.hpp"
using namespace std;
int main()
{
    EnableScreen();
    //处理新连接到来的模块，连接管理器
    Listener listen(gport);
    //处理普通sockfd模块，IO管理器
    NetCal cal;
    PackageParse service(std::bind(&NetCal::Caculator,&cal, std::placeholders::_1));
    handler_t process = std::bind(&PackageParse::Excute, &service, std::placeholders::_1);
    HandlerConnection handlers(process);
    //主模块。事件派发器
    std::unique_ptr<Reactor> server = std::make_unique<Reactor>();

    handler_t OnConnection = std::bind(&Listener::Accepter, &listen, std::placeholders::_1);
    server->SetOnConnection(OnConnection);

    handler_t OnRecv=std::bind(&HandlerConnection::HandlerRecver,&handlers,std::placeholders::_1);
    handler_t OnSend=std::bind(&HandlerConnection::HandlerSender,&handlers,std::placeholders::_1);
    handler_t OnExcept=std::bind(&HandlerConnection::HandlerExcepter,&handlers,std::placeholders::_1);
    server->SetNormalConnection(OnRecv, OnSend, OnExcept);

    InetAddr addr("0.0.0.0",gport);
    server->AddConnection(listen.Sockfd(), EPOLLIN | EPOLLET, addr,LISTENCONNECTION);
    server->Dispatcher();
}